package com.lbd.gulimall.ware.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ProjectName: gulimall
 * @Package: com.lbd.gulimall.ware.config
 * @ClassName: AutoFillHandler
 * @Author: linbd
 * @Description:
 * @Date: 2021/6/27 16:57
 */
@Component
public class AutoFillHandler implements MetaObjectHandler {
    // 插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        //fieldName就是实体类字段
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    // 更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
